package com.FundamentalDemos.Array;

import java.util.Random;
import java.util.Scanner;

public class 随机排名 {
    public static void main(String[] args) {
        int[] staff = new int[10];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < staff.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个员工的工号:");
            staff[i] = sc.nextInt();
        }


        System.out.println("排名前员工的工号序列如下:");
        for (int i = 0; i < staff.length; i++) {
            System.out.print(staff[i] + " ");
        }
        System.out.println();


        Random rd = new Random();
        int temp, rdNumber;


        //随机排名
        for (int i = 0; i < staff.length; i++) {
            rdNumber = rd.nextInt(staff.length);
            temp = staff[rdNumber];
            staff[rdNumber] = staff[i];
            staff[i] = temp;
            System.out.println("\nstaff[" + i + "]与staff[" + rdNumber + "]交换了!");
        }


        System.out.println("随机排名后员工的工号序列如下:");
        for (int i = 0; i < staff.length; i++) {
            System.out.print(staff[i] + " ");
        }
        System.out.println();

    }
}
